/*
################################################################################################################################# Included
0 9    B  Allow/prevent seeing the names of the people around : @shownames=<y/n>     
1 9    B  Allow/prevent seeing all the hovertexts : @showhovertextall=<y/n>     
2 9    B  Allow/prevent seeing the hovertexts on the HUD of the user : @showhovertexthud=<y/n>     
3 9    B  Allow/prevent seeing the hovertexts in-world : @showhovertextworld=<y/n>
#################################################################################################################################
*/
integer attachment = TRUE;
integer relaychannel = -1812221819;
string cmdname;
key victim;
list gMenu=[];
list statesMenu=[0,0,0,0];
list gAvatarAllow;
key ToucherID;
integer gMenuLink =1337;
integer gDemon =1338;
integer gPlugin =1339;
integer gVic =1329;
integer channel_dialog;
integer listen_id;
string msg ="Hover Test";
list sideMenu=[" ","Back"," "];

Debug(string _text)
{
	llSay(DEBUG_CHANNEL, _text);
}

llRlvSay(string command)
{
	if(attachment==TRUE)
	{
		llOwnerSay("@"+command);
	}
	else
	{
		llSay(relaychannel,cmdname + "," + (string)victim  + "," + "@"+command);
	}
}

MakeRLVState()
{
	if(attachment==TRUE)
	{
		//onRez we make this to be secure if its an attachmentttt
		if(llList2Integer(statesMenu,0)==1)llRlvSay("shownames=n");
		if(llList2Integer(statesMenu,1)==1)llRlvSay("showhovertextall=n");
		if(llList2Integer(statesMenu,2)==1)llRlvSay("showhovertexthud=n");
		if(llList2Integer(statesMenu,3)==1)llRlvSay("showhovertextworld=n");
	}
}

llLRP(integer element_new, integer placeinlist)
{
	statesMenu = llListReplaceList(statesMenu, [element_new], placeinlist, placeinlist);
}

makeMenu()
{
	gMenu=[];
	gMenu+=sideMenu;
	if(llList2Integer(statesMenu,0)==1)gMenu+="[x]Names";
	else gMenu+="[ ]Names";
	if(llList2Integer(statesMenu,1)==1)gMenu+="[x]All Hover";
	else gMenu+="[ ]All Hover";
	if(llList2Integer(statesMenu,2)==1)gMenu+="[x]Hud Hover";
	else gMenu+="[ ]Hud Hover";
	if(llList2Integer(statesMenu,3)==1)gMenu+="[x]Inworld Hover";
	else gMenu+="[ ]Inworld Hover";


	//Than display
	channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
	listen_id = llListen( channel_dialog, "", NULL_KEY, "");
	llDialog(ToucherID, msg,gMenu, channel_dialog);
	llSetTimerEvent(45.0);
}

default {
    state_entry() 
    {
    	    
    }
    
    listen(integer channel, string name, key id, string message)
    {
		llListenRemove(listen_id);
		llSetTimerEvent(0.0);

    	if(message=="[x]Names"){llLRP(0,0);llRlvSay("shownames=y");makeMenu();}
		if(message=="[ ]Names"){llLRP(1,0);llRlvSay("shownames=n");makeMenu();}
		if(message=="[x]All Hover"){llLRP(0,1);llRlvSay("showhovertextall=y");makeMenu();}
		if(message=="[ ]All Hover"){llLRP(1,1);llRlvSay("showhovertextall=n");makeMenu();}
		if(message=="[x]Hud Hover"){llLRP(0,2);llRlvSay("showhovertexthud=y");makeMenu();}
		if(message=="[ ]Hud Hover"){llLRP(1,2);llRlvSay("showhovertexthud=n");makeMenu();}
		if(message=="[x]Inworld Hover"){llLRP(0,3);llRlvSay("showhovertextworld=y");makeMenu();}
		if(message=="[ ]Inworld Hover"){llLRP(1,3);llRlvSay("showhovertextworld=n");makeMenu();}
		if(message=="Back")llMessageLinked(LINK_THIS, gMenuLink, "DV_MAIN_RLV", ToucherID);
		
    }
    
    on_rez(integer on)
    {
    
    }
    
    link_message(integer sender, integer num, string str, key id)
  	{
  		
  		if(num ==gMenuLink)
  		{
  			if(str==llGetScriptName())
  			{
  				llMessageLinked(LINK_THIS, gDemon, llGetScriptName(), NULL_KEY);
  				ToucherID=id;
  				makeMenu();
  			}
  		}
  		if(num ==gDemon)
  		{
  			if(str =="attachment")attachment=TRUE;
  			else if(str =="device")attachment=FALSE;
  			else if(str!=llGetScriptName())
  			{
				llListenRemove(listen_id);

  			}
  		}
  		if(num==gPlugin)
  		{
  			if(str=="ON_REZ")
  			{
  				MakeRLVState();
  			}
  			if(str=="RESET")
  			{
  				statesMenu=[0,0,0,0];
  			}
  		}
  		if(num==gVic)
  		{
  				victim=(key)str;
  				cmdname = (string)llGetKey();
  		}
  	}
  	
  	timer()
    {
    	llSetTimerEvent(0.0);
    	llListenRemove(listen_id);
    }
}
